//
//  SVRadialGradientLayer.swift
//  Valentine-Swift
//
//  Created by 陆文宇 on 2017/1/31.
//  Copyright © 2017年 陆文宇. All rights reserved.
//

import UIKit

class SVRadialGradientLayer: CALayer {
    
    var gradientCenter: CGPoint?
    
    override func draw(in ctx: CGContext) {
        let locationsCount: size_t = 2
        let locations: Array<CGFloat> = [0, 1]
        let colors: Array<CGFloat> = [0, 0, 0, 0, 0, 0, 0, 0.75]
        let colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB()
        let gradient: CGGradient = CGGradient(colorSpace: colorSpace, colorComponents: colors, locations: locations, count: locationsCount)!
        
        let radius: CGFloat = min(bounds.size.width, bounds.size.height)
        ctx.drawRadialGradient(gradient, startCenter: gradientCenter!, startRadius: 0, endCenter: gradientCenter!, endRadius: radius, options: .drawsAfterEndLocation)
    }

}
